package api

import (
	"api-client/pkg"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func Upload(c *gin.Context) {
	// 单文件
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "./" + file.Filename
	pkg.UploadOss(dst)
	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, "./files/"+file.Filename)
	if file.Size > 1024*1024*500 {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "文件大小不能超过500MB",
		})
		return
	}
	if file.Filename != "mp4" {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "文件格式错误",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传成功",
	})
}
